<?php
$tr = Zend_Registry::get('Zend_Translate');

$posts = $this->posts;

$page_number = $this->page_number;
$page_count = $this->page_count;

$first = 1;
$latest = $page_count;

$next = $page_number +1;
$prev = $page_number -1;

// Next, previous first and last page links
$first_link = $this->url(array('controller' => 'index', 'action' => 'index', 'page' => $first), '', false);
$last_link = $this->url(array('controller' => 'index', 'action' => 'index', 'page' => $latest), '', false);
$next_link = $this->url(array('controller' => 'index', 'action' => 'index', 'page' => $next), '', false);
$prev_link = $this->url(array('controller' => 'index', 'action' => 'index', 'page' => $prev), '', false);

$add_link_first = $page_number != $first ? true : false;
$add_link_last = $page_number != $latest ? true : false;

$nav = null;
$nav .= '<ul>';
$nav .= '<li class="button button-first">';    if ($add_link_first) {$nav .= '<a href="' . $first_link . '">';} $nav .= $tr->_("First");    if ($add_link_first) {$nav .= '</a>';} $nav .= '</li>';
$nav .= '<li class="button button-previous">'; if ($add_link_first) {$nav .= '<a href="' . $prev_link . '">';}  $nav .= $tr->_("Previous"); if ($add_link_first) {$nav .= '</a>';} $nav .= '</li>';
$nav .= '<li class="button button-next">';     if ($add_link_last)  {$nav .= '<a href="' . $next_link . '">';}  $nav .= $tr->_("Next");     if ($add_link_last)  {$nav .= '</a>';} $nav .= '</li>';
$nav .= '<li class="button button-latest">';   if ($add_link_last)  {$nav .= '<a href="' . $last_link . '">';}  $nav .= $tr->_("Latest");   if ($add_link_last)  {$nav .= '</a>';} $nav .= '</li>';
$nav .= '</ul>';
$nav .= "\n";

?>

<h2><?php echo $tr->_("Front page");?></h2>

<div id="posts" class="external-urls">

<div id="intro">
<?php echo $this->introtext;?>
</div>

<br />

<div class="navigation"><?php echo $nav;?></div>
<?php
if(is_array($posts) && !empty($posts))
{
  $d = new Zend_Date();

  for($i=0; $i<count($posts); $i++)
  {
    $subject = $this->escape($posts[$i]['subject']);
    $txt = $posts[$i]['content'];
    $author = $this->escape($posts[$i]['name']);
    $d->setTimestamp($posts[$i]['uadded']);
    
    echo '<div class="entry">';
    echo '<div class="entry-subject"><h3>';
    echo $subject;
    echo '</h3></div>';
    echo '<div class="entry-content">';
    echo $txt;
    echo '</div>';

    echo '<div class="entry-author">';
    echo "$author " . $d->toString($this->dateformat);
    echo ' (' . sprintf($tr->_("%s ago"), $this->relativetime($posts[$i]['uadded'])) . ')';
    echo '</div>';

    echo "</div>\n";
  } // /for
}
else
{
  echo $tr->_('No posts');
}
?>
<div class="navigation"><?php echo $nav;?></div>
</div>

<div id="statistics">

<div id="comics-latest-comments" class="statistics">
<?php
$l = $this->comments;

if(is_array($l) && !empty($l))
{
  echo '<span class="title">' . $tr->_('Latest comic comments') . "</span>\n";

  echo '<table width="100%">' . "\n";

  echo '<col width="1" />' . "\n";
  echo '<col width="100%" />' . "\n";

  echo '<tr>';
  echo '<td></td>';
  echo '<td></td>';
  echo "</tr>\n";

  $even = true;

  for($i=0; $i<count($l); $i++)
  {
    $class = null;

    if($even)
    {
      $class = 'even ';
    }
    else
    {
      $class = 'odd ';
    }

    $id = $l[$i]['comicid'];
    $title = $this->escape($l[$i]['title']);
    $comment = strip_tags($l[$i]['comment']);
    $country = $l[$i]['country'];

    $link = $this->url(array('id' => $id, 'name' => $title), 'comic', true);

    echo sprintf('<tr class="%s">', trim($class));
    echo '<td align="center"><a href="' . $link . '" title="' . $title . '">#' . $id . '</a></td>';
    echo '<td align="left"><img src="/images/flags18x12/' . $country . '.png" alt="' . $country. '" width="18" height="12" /> ' . $comment . '</td>';
    echo "</tr>\n";

    $even = !$even;
  }

  echo "</table>\n";
}
?>
</div>


<div id="comics-top" class="statistics">
<?php
$l = $this->topcomics;

if(is_array($l) && !empty($l))
{
  echo '<span class="title">' . $tr->_('Top ten comics') . "</span>\n";
  
  echo '<table width="100%">' . "\n";

  echo '<col width="1" />' . "\n";
  echo '<col width="100%" />' . "\n";

  echo '<tr>';
  echo '<td></td>';
  echo '<td></td>';
  echo "</tr>\n";

  $even = true;

  for($i=0; $i<count($l); $i++)
  {
    $class = null;

    if($even)
    {
      $class = 'even ';
    }
    else
    {
      $class = 'odd ';
    }

    $id = $l[$i]['id'];
    $name = $this->escape($l[$i]['name']);
    $rating = $l[$i]['avgrate'];

    $link = $this->url(array('id' => $id, 'name' => $name), 'comic', true);

    echo sprintf('<tr class="%s">', trim($class));
    echo '<td align="center">' . round($rating, 2) . '</td>';
    echo '<td align="left"><a href="' . $link . '">' . $name . '</a></td>';
    echo "</tr>\n";

    $even = !$even;
  }

  echo "</table>\n";
}
?>
</div>

<div id="comics-bottom" class="statistics">
<?php
$l = $this->bottomcomics;

if (is_array($l) && !empty($l))
{
  echo '<span class="title">' . $tr->_('Worst ten comics') . "</span>\n";

  echo '<table width="100%">' . "\n";

  echo '<col width="1" />' . "\n";
  echo '<col width="100%" />' . "\n";

  echo '<tr>';
  echo '<td></td>';
  echo '<td></td>';
  echo "</tr>\n";

  $even = true;

  for($i=0; $i<count($l); $i++)
  {
    $class = null;

    if($even)
    {
      $class = 'even ';
    }
    else
    {
      $class = 'odd ';
    }

    $id = $l[$i]['id'];
    $name = $this->escape($l[$i]['name']);
    $rating = $l[$i]['avgrate'];

    $link = $this->url(array('id' => $id, 'name' => $name), 'comic', true);

    echo sprintf('<tr class="%s">', trim($class));
    echo '<td align="center">' . round($rating, 2) . '</td>';
    echo '<td align="left"><a href="' . $link . '">' . $name . '</a></td>';
    echo "</tr>\n";

    $even = !$even;
  }

  echo "</table>\n";
}
?>
</div>

</div> <!-- statistics -->